package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;


@Entity
@Table(name = "enrolled_patients", catalog = "bms")
public class EnrolledPatients  implements java.io.Serializable, Comparable<EnrolledPatients> {

    // Fields

    private Integer id;
    private Integer patientOrder ;
    private Integer targetEnrolledAmount;
    private Integer targetEnrolledRandomized;
    private Date targetEnrolledDate;
    private String comment;
    private ProtocoloCompromisopais protocoloCompromisopais;
    private EpCategory category;
    // Constructors

    /** default constructor */
    public EnrolledPatients() {
    }

    /** full constructor */
    public EnrolledPatients(ProtocoloCompromisopais protocoloCompromisopais, Integer patientOrder , Integer targetEnrolledAmount,
                Date targetEnrolledDate,  String comment) {
        this.protocoloCompromisopais = protocoloCompromisopais;
        this.patientOrder  = patientOrder ;
        this.targetEnrolledAmount = targetEnrolledAmount;
        this.targetEnrolledDate = targetEnrolledDate;
        this.comment = comment;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne()
    @LazyCollection(LazyCollectionOption.FALSE)
    @JoinColumns( {
            @JoinColumn(name = "protocoloid", referencedColumnName = "protocoloid", nullable = false),
            @JoinColumn(name = "compromisopaisid", referencedColumnName = "compromisopaisid", nullable = false) })
    public ProtocoloCompromisopais getProtocoloCompromisopais() {
        return this.protocoloCompromisopais;
    }

    public void setProtocoloCompromisopais(ProtocoloCompromisopais protocoloCompromisopais) {
        this.protocoloCompromisopais = protocoloCompromisopais;
    }

    @Column(name = "patientOrder")
    public Integer getPatientOrder() {
        return patientOrder ;
    }

    public void setPatientOrder(Integer patientOrder ) {
        this.patientOrder = patientOrder ;
    }

    @Column(name = "targetEnrolledAmount")
    public Integer getTargetEnrolledAmount() {
        return targetEnrolledAmount;
    }

    public void setTargetEnrolledAmount(Integer targetEnrolledAmount) {
        this.targetEnrolledAmount = targetEnrolledAmount;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "targetEnrolledDate", length = 10)
    public Date getTargetEnrolledDate() {
        return targetEnrolledDate;
    }

    public void setTargetEnrolledDate(Date targetEnrolledDate) {
        this.targetEnrolledDate = targetEnrolledDate;
    }

    @Column(name = "comment")
    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Column(name = "targetEnrolledRandomized")
    public Integer getTargetEnrolledRandomized() {
        return targetEnrolledRandomized;
    }

    public void setTargetEnrolledRandomized(Integer targetEnrolledRandomized) {
        this.targetEnrolledRandomized = targetEnrolledRandomized;
    }

    public int compareTo(EnrolledPatients o){
        return this.patientOrder.compareTo(o.patientOrder);
    }

    public enum EpCategory{
        Drug(0,"Drug"),
        Amendment(1,"Amendment"),
        Recruitment(2,"Recruitment"),
        Other(3,"Other");

        private String desc;
        private Integer id;

        EpCategory(){
            this.id = -1;
            this.desc = "";
        }

        EpCategory(Integer id,String name){
            this.id = id;
            this.desc = name;
        }

        public String getDescription() {
            return this.desc;
        }

        public Integer getId() {
            return this.id;
        }


        public void setId(Integer id) {
            this.id = id;
        }
    }

    @Enumerated(EnumType.ORDINAL)
    public EpCategory getCategory() {
        return category;
    }

    public void setCategory(EpCategory category) {
        this.category = category;
    }

    public void setCategory(String id) {
        this.category = EnrolledPatients.EpCategory.values()[Integer.parseInt(id)];
    }

}